﻿
/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 12/07/2010
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
namespace CommonTagTime.DataAccess
{
    public class daoImageProduct
    {
        public daoImageProduct()
        {

        }

        public bool Insert(ImageProduct objImageProduct)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[3];          
            try
            {
                para[0] = new SqlParameter(busImageProduct.FILENAME, SqlDbType.VarChar);
                para[0].Value =objImageProduct.FileName;

                para[1] = new SqlParameter(busImageProduct.DESCRIPTION, SqlDbType.NVarChar);
                para[1].Value = objImageProduct.Description;

                para[2] = new SqlParameter(busImageProduct.PRODUCTID, SqlDbType.Int);
                para[2].Value = objImageProduct.ProductID;
                result = clsSQL.SPExecute("ImageProduct_Insert", para);               

            }
            catch (Exception ex)
            {               
                clsFile.WriteLog("daoCategory", "Category_Insert(Category category)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
        public ImageProductCollection GetListByProductID(int productID)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            ImageProductCollection items = new ImageProductCollection();

            try
            {
                para[0] = new SqlParameter(busImageProduct.PRODUCTID, SqlDbType.Int);
                para[0].Value = productID;
                de = clsSQL.SPDataReader("ImageProduct_GetListByProductID",para);
                while (de.Read())
                {
                    ImageProduct item = Load(de);
                    items.Add(item);
                }

                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("ProductCategory", "List(GetListByProductID)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }

            return items;
        }
        private ImageProduct Load(IDataReader de)
        {
            ImageProduct item = new ImageProduct();
            item.FileName = clsConvert.DbToString("FileName", de);
            item.ProductID = clsConvert.DbToInt("ProductID", de);
            item.Description = clsConvert.DbToString("Description", de);
            item.ImageProductID = clsConvert.DbToInt("ImageProductID", de);
            return item;
            // de.P
            //int intLogID = Convert.ToInt32(_comm.Parameters["@LogID"].Value);
        }
        public bool Delete(int imageProductID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];           
            try
            {
                para[0] = new SqlParameter(busImageProduct.IMAGEPRODUCTID, SqlDbType.Int);
                para[0].Value = imageProductID;
                result = clsSQL.SPExecute("ImageProduct_Delete", para);               

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoImageProduct", "Delete(daoImageProduct imageProductID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
        public bool DeleteByProductID(int ProductID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busImageProduct.PRODUCTID, SqlDbType.Int);
                para[0].Value = ProductID;
                result = clsSQL.SPExecute("ImageProduct_DeleteByProductID", para);

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoImageProduct", "DeleteByProductID(daoImageProduct ProductID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
    }
}
